package hyit.app.dao.proxy;

import hyit.app.dao.IClientUserDAO;
import hyit.app.dao.impl.ClientUserDAOImpl;
import hyit.app.dbc.DatabaseConnection;
import hyit.app.model.ClientUser;

public class ClientUserDAOProxy implements IClientUserDAO {
	private DatabaseConnection dbc = null;
	private IClientUserDAO dao = null;

	public ClientUserDAOProxy() throws Exception {
		this.dbc = new DatabaseConnection();
		this.dao = new ClientUserDAOImpl(this.dbc.getConnection());
	}

	@Override
	public boolean doCreate(ClientUser clientUser) throws Exception {
		boolean flag = false;
		try {
			if (this.dao.findById(clientUser.getMemberId()) == null) {
				flag = this.dao.doCreate(clientUser);
			}
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public boolean update(ClientUser clientUser) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.update(clientUser);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public boolean delete(ClientUser clientUser) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public ClientUser findById(Long number) throws Exception {
		ClientUser clientUser = null;
		try {
			clientUser = this.dao.findById(number);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return clientUser;
	}

	@Override
	public ClientUser validate(Long memberId, String password) throws Exception {
		ClientUser clientUser = null;
		try {
			clientUser = this.dao.validate(memberId, password);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return clientUser;
	}

	@Override
	public ClientUser validate(String cardMac) throws Exception {
		ClientUser clientUser = null;
		try {
			clientUser = this.dao.validate(cardMac);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return clientUser;
	}

}
